﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using YJKRevitArea.AreaSet;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Revit;
using YJKArchUtils.Utils;
using YJKAreaStatistic.DataDefine;
using YJKRevitBase.TopologySuite;
using YJKRevitKernel.CurveUtility;
using YJKRevitKernel.RevitTopologySuite;
using YJKGeometryFuncs;

namespace YJKAreaStatistic.Manage
{
	internal class ModifyBonudaryManager
	{
		public static bool GetAreaInfo(ExternalCommandData m_revit, List<Curve> lstDrawCurves, List<Room> lstSelectRooms, int m_nClickCellRow, List<KeyValuePair<Area, AreaBoundaryBean>> dicAreaToBoundary, ref List<Area> lstNotNewArea, ref List<Area> lstNewArea)
		{
			string a = "";
			Document document = m_revit.Application.ActiveUIDocument.Document;
			List<KeyValuePair<RevitPolygonDataBean, List<Room>>> list = new List<KeyValuePair<RevitPolygonDataBean, List<Room>>>();
			List<KeyValuePair<RevitPolygonDataBean, List<Room>>> list2 = new List<KeyValuePair<RevitPolygonDataBean, List<Room>>>();
			ModifyBonudaryManager.judgeCurRoomIsInArea(document, dicAreaToBoundary, m_nClickCellRow, ref lstSelectRooms);
			if (lstSelectRooms.Count != 0)
			{
				List<XYZ> list3 = new List<XYZ>();
				List<CurveInformationBean> list4 = new List<CurveInformationBean>();
				try
				{
					list4 = AreaCreator.GetRoomCurveBeansWithoutInstance(document, lstSelectRooms, false);
					AreaCreator.AdjustCurves(ref list4, ref list3, document);
					foreach (List<CurveInformationBean> list5 in AreaCreator.GetLargestClosedAreas(list4))
					{
						CurveLoop curveLoop = new CurveLoop();
						foreach (CurveInformationBean curveInformationBean in list5)
						{
							curveLoop.Append(curveInformationBean.ThisCurve);
						}
						RevitPolygonDataBean key = new RevitPolygonDataBean(curveLoop, new List<CurveLoop>(), 3);
						list.Add(new KeyValuePair<RevitPolygonDataBean, List<Room>>(key, lstSelectRooms));
					}
					list4.Clear();
				}
				catch (Exception)
				{
					return false;
				}
			}
			if (lstDrawCurves.Count == 0 && list.Count == 0)
			{
				return false;
			}
			foreach (KeyValuePair<Area, AreaBoundaryBean> keyValuePair in dicAreaToBoundary)
			{
				if (!YJKArchUtils.Utils.Geometry.LessThan(keyValuePair.Key.Area, 1.0))
				{
					list2.Clear();
					double area = keyValuePair.Key.Area;
					ModifyBonudaryManager.HaxExtensibleStorageInArea(keyValuePair.Key, ref ModifyBonudaryManager.m_areaType);
					Parameter parameter = keyValuePair.Key.GetParameter("名称");
					if (parameter != null)
					{
						a = parameter.AsString();
					}
					if (!(a == ""))
					{
						List<Curve> lstOneAreaBoundary = keyValuePair.Value.lstOneAreaBoundary;
						RevitPolygonDataBean onePolygon = null;
						try
						{
							onePolygon = new RevitPolygonDataBean(CurveLoop.Create(lstOneAreaBoundary), new List<CurveLoop>(), 3);
						}
						catch (Exception)
						{
							lstNotNewArea.Add(keyValuePair.Key);
							continue;
						}
						List<RevitPolygonDataBean> list6 = null;
						List<RevitPolygonDataBean> list7 = null;
						if (lstDrawCurves.Count != 0 && lstOneAreaBoundary.Count != 0)
						{
							if (!YJKGeometryFuncs.Geometry.IsEqual(lstOneAreaBoundary.First<Curve>().GetEndPoint(0).Z, lstDrawCurves.First<Curve>().GetEndPoint(0).Z))
							{
								using (List<Curve>.Enumerator enumerator4 = lstDrawCurves.GetEnumerator())
								{
									while (enumerator4.MoveNext())
									{
										Curve inputCurve = enumerator4.Current;
										lstOneAreaBoundary.Add(CurveUtilityMethod.TransformCurveAtZAixs(inputCurve, lstOneAreaBoundary.First<Curve>().GetEndPoint(0).Z, true));
									}
									goto IL_26D;
								}
							}
							lstOneAreaBoundary.AddRange(lstDrawCurves);
						}
						IL_26D:
						RevitPolygonFinder revitPolygonFinder = new RevitPolygonFinder();
						try
						{
							if (revitPolygonFinder.TryGetPolygon(lstOneAreaBoundary, out list6, out list7, true, 3, false))
							{
								if (ModifyBonudaryManager.judgeIsNeedCreateArea(keyValuePair.Key, list7))
								{
									lstNotNewArea.Add(keyValuePair.Key);
								}
								foreach (RevitPolygonDataBean key2 in list7)
								{
									list2.Add(new KeyValuePair<RevitPolygonDataBean, List<Room>>(key2, new List<Room>()));
								}
								list2.AddRange(list);
								ModifyBonudaryManager.CreateNewArea(document, keyValuePair.Key, onePolygon, list2, dicAreaToBoundary, ref lstNewArea);
							}
							else
							{
								lstNotNewArea.Add(keyValuePair.Key);
							}
						}
						catch (Exception)
						{
							return false;
						}
					}
				}
			}
			return true;
		}

		private static bool judgeIsNeedCreateArea(Area area, List<RevitPolygonDataBean> lstCreatedPolyDataBean)
		{
			List<bool> list = new List<bool>();
			using (List<RevitPolygonDataBean>.Enumerator enumerator = lstCreatedPolyDataBean.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (YJKGeometryFuncs.Geometry.LessThan(double.Parse(enumerator.Current.Area.ToString()), area.Area, 0.1))
					{
						list.Add(false);
					}
					else
					{
						list.Add(true);
					}
				}
			}
			return !list.Contains(true);
		}

		private static void CreateNewArea(Autodesk.Revit.DB.Document doc, Area areaTmp, RevitPolygonDataBean onePolygon, List<KeyValuePair<RevitPolygonDataBean, List<Room>>> lstRoomPolygonDataBean, List<KeyValuePair<Area, AreaBoundaryBean>> dicAreaToBoundary, ref List<Area> lstNewArea)
		{
			bool flag = false;
			XYZ xyz = null;
			List<ElementId> list = new List<ElementId>();
			InsertDataManager.ReadExtensibleStorageFromArea(areaTmp, ref list);
			try
			{
				foreach (KeyValuePair<RevitPolygonDataBean, List<Room>> keyValuePair in lstRoomPolygonDataBean)
				{
					bool flag2 = false;
					bool flag3 = ModifyBonudaryManager.m_useRelateOperater.TryGetPolygonRelate(onePolygon, keyValuePair.Key, out ModifyBonudaryManager.tempRelate);
					if (!flag && flag3 && ModifyBonudaryManager.tempRelate != TopologyRelateKindEnum.Disjoint && ModifyBonudaryManager.tempRelate != TopologyRelateKindEnum.Touches && !YJKArchUtils.Utils.Geometry.LessThan(double.Parse(keyValuePair.Key.Area.ToString()), 1.0))
					{
						ModifyBonudaryManager.DeleteArea(doc, areaTmp.Id, dicAreaToBoundary);
						flag = true;
						flag2 = true;
					}
					Room room = null;
					if (ModifyBonudaryManager.GetAreaInnerPt(keyValuePair.Key, out xyz) && !YJKArchUtils.Utils.Geometry.LessThan(double.Parse(keyValuePair.Key.Area.ToString()), 1.0) && !ModifyBonudaryManager.IsExistSamePt(ModifyBonudaryManager.lstAreaInnerPts, xyz))
					{
						foreach (Curve curve in keyValuePair.Key.ShellCurveLoop)
						{
							if (curve != null)
							{
								doc.Create.NewAreaBoundaryLine(doc.ActiveView.SketchPlane, curve, doc.ActiveView as ViewPlan);
							}
						}
						UV uv = new UV(xyz.X, xyz.Y);
						Area area = doc.Create.NewArea(doc.ActiveView as ViewPlan, uv);
						if (area != null)
						{
							lstNewArea.Add(area);
							ModifyBonudaryManager.lstAreaInnerPts.Add(xyz);
						}
						if (flag2 && ModifyBonudaryManager.m_areaType == AreaType.AT_Fill)
						{
							AreaTag areaTag = doc.Create.NewAreaTag(doc.ActiveView as ViewPlan, area, uv);
							AreaTagType areaTagType = ModifyBonudaryManager.GetAreaTagType(doc);
							if (areaTagType != null)
							{
								areaTag.AreaTagType = areaTagType;
							}
						}
						else if (flag2 && ModifyBonudaryManager.m_areaType == AreaType.AT_Suite)
						{
							if (list.Count != 0)
							{
								room = (doc.GetElement(list.First<ElementId>()) as Room);
							}
						}
						else if (ModifyBonudaryManager.IsExistHouseType(keyValuePair.Value))
						{
							room = keyValuePair.Value.First<Room>();
						}
						if (ModifyBonudaryManager.m_areaType != AreaType.AT_Fill && room != null)
						{
							ModifyBonudaryManager.AddSharedParaToArea(doc, area, room);
							doc.Regenerate();
							ModifyBonudaryManager.AddAreaTag(doc, area);
							string suiteName = room.GetParameter("户型名称").AsString().Trim();
							string hoomNumb = room.GetParameter("户型编号").AsString().Trim();
							InsertDataManager.WriteExtensibleStorageToArea(area, AreaType.AT_Suite, suiteName, hoomNumb, list);
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}

		public static void ClearUpCaching()
		{
			ModifyBonudaryManager.lstAreaInnerPts.Clear();
		}

		private static bool IsExistSamePt(List<XYZ> lstExistPt, XYZ curPt)
		{
			try
			{
				using (List<XYZ>.Enumerator enumerator = lstExistPt.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						if (enumerator.Current.IsAlmostEqualTo(curPt, 0.01))
						{
							return true;
						}
					}
				}
			}
			catch (Exception)
			{
				return false;
			}
			return false;
		}

		private static bool IsExistHouseType(List<Room> lstRooms)
		{
			foreach (Room elem in lstRooms)
			{
				try
				{
					if (elem.GetParameter("户型名称").AsString().Trim() != "")
					{
						return true;
					}
				}
				catch (Exception)
				{
					return false;
				}
			}
			return false;
		}

		private static Dictionary<string, List<Room>> GroupingRooms(List<Room> rooms)
		{
			List<Room> list = new List<Room>();
			Dictionary<string, List<Room>> dictionary = new Dictionary<string, List<Room>>();
			foreach (Room room in rooms)
			{
				try
				{
					string text = room.GetParameter("楼号").AsString().Trim();
					string text2 = room.GetParameter("单元").AsString().Trim();
					string text3 = room.GetParameter("户型名称").AsString().Trim();
					string text4 = room.GetParameter("户型编号").AsString().Trim();
					if (text3.Length != 0)
					{
						string key = string.Concat(new string[]
						{
							text,
							"_",
							text2,
							"_",
							text3,
							"_",
							text4
						});
						if (dictionary.ContainsKey(key))
						{
							dictionary[key].Add(room);
						}
						else
						{
							dictionary.Add(key, new List<Room>
							{
								room
							});
						}
					}
				}
				catch
				{
					list.Add(room);
				}
			}
			dictionary.Add("", list);
			return dictionary;
		}

		private static void AddSharedParaToArea(Autodesk.Revit.DB.Document doc, Area area, Room room)
		{
            BuiltInCategory integerValue = (BuiltInCategory)area.Category.Id.IntegerValue;
			Dictionary<string, ParameterType> dictionary = new Dictionary<string, ParameterType>();
			if (area.GetParameter("区域单元") == null)
			{
                dictionary.Add("区域单元", (ParameterType)1);
			}
			if (area.GetParameter("区域楼号") == null)
			{
                dictionary.Add("区域楼号", (ParameterType)1);
			}
			if (area.GetParameter("区域编号") == null)
			{
                dictionary.Add("区域编号", (ParameterType)1);
			}
			if (dictionary.Count > 0)
			{
				SharedParameter.InsertSharedParameter(doc, integerValue, "区域信息", dictionary, true, true);
			}
			string text = room.GetParameter("户型名称").AsString().Trim();
			string text2 = room.GetParameter("户型编号").AsString().Trim();
			string text3 = room.GetParameter("单元").AsString().Trim();
			string text4 = room.GetParameter("楼号").AsString().Trim();
			area.GetParameter("区域编号").Set(text2);
			area.GetParameter("区域单元").Set(text3);
			area.GetParameter("区域楼号").Set(text4);
			area.GetParameter("名称").Set(text);
		}

		private static void AddAreaTag(Autodesk.Revit.DB.Document doc, Area area)
		{
			LocationPoint locationPoint = area.Location as LocationPoint;
			UV uv = new UV(locationPoint.Point.X, locationPoint.Point.Y);
			ViewPlan viewPlan = doc.ActiveView as ViewPlan;
			List<string> insideLabels = ModifyBonudaryManager.GetInsideLabels(area);
			ModifyBonudaryManager.LoadAreaTagFamily(doc);
			if (1 == insideLabels.Count)
			{
				AreaTag areaTag = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag.AreaTagType = areaTagTypeByName;
				areaTag.GetParameter("引线").Set(0);
				return;
			}
			if (2 == insideLabels.Count)
			{
				AreaTag areaTag2 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName2 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag2.AreaTagType = areaTagTypeByName2;
				areaTag2.GetParameter("引线").Set(0);
				UV uv2 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag3 = doc.Create.NewAreaTag(viewPlan, area, uv2);
				AreaTagType areaTagTypeByName3 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[1]);
				areaTag3.AreaTagType = areaTagTypeByName3;
				areaTag3.GetParameter("引线").Set(0);
				return;
			}
			if (3 == insideLabels.Count)
			{
				UV uv3 = new UV(uv.U, uv.V + 1.4);
				AreaTag areaTag4 = doc.Create.NewAreaTag(viewPlan, area, uv3);
				AreaTagType areaTagTypeByName4 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag4.AreaTagType = areaTagTypeByName4;
				areaTag4.GetParameter("引线").Set(0);
				AreaTag areaTag5 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName5 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[1]);
				areaTag5.AreaTagType = areaTagTypeByName5;
				areaTag5.GetParameter("引线").Set(0);
				uv3 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag6 = doc.Create.NewAreaTag(viewPlan, area, uv3);
				AreaTagType areaTagTypeByName6 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[2]);
				areaTag6.AreaTagType = areaTagTypeByName6;
				areaTag6.GetParameter("引线").Set(0);
				return;
			}
			if (4 == insideLabels.Count)
			{
				UV uv4 = new UV(uv.U, uv.V + 1.4);
				AreaTag areaTag7 = doc.Create.NewAreaTag(viewPlan, area, uv4);
				AreaTagType areaTagTypeByName7 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag7.AreaTagType = areaTagTypeByName7;
				areaTag7.GetParameter("引线").Set(0);
				AreaTag areaTag8 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName8 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[1]);
				areaTag8.AreaTagType = areaTagTypeByName8;
				areaTag8.GetParameter("引线").Set(0);
				uv4 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag9 = doc.Create.NewAreaTag(viewPlan, area, uv4);
				AreaTagType areaTagTypeByName9 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[2]);
				areaTag9.AreaTagType = areaTagTypeByName9;
				areaTag9.GetParameter("引线").Set(0);
				uv4 = new UV(uv.U, uv.V - 2.8);
				AreaTag areaTag10 = doc.Create.NewAreaTag(viewPlan, area, uv4);
				AreaTagType areaTagTypeByName10 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[3]);
				areaTag10.AreaTagType = areaTagTypeByName10;
				areaTag10.GetParameter("引线").Set(0);
				return;
			}
			if (5 == insideLabels.Count)
			{
				UV uv5 = new UV(uv.U, uv.V + 2.8);
				AreaTag areaTag11 = doc.Create.NewAreaTag(viewPlan, area, uv5);
				AreaTagType areaTagTypeByName11 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[0]);
				areaTag11.AreaTagType = areaTagTypeByName11;
				areaTag11.GetParameter("引线").Set(0);
				uv5 = new UV(uv.U, uv.V + 1.4);
				AreaTag areaTag12 = doc.Create.NewAreaTag(viewPlan, area, uv5);
				AreaTagType areaTagTypeByName12 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[1]);
				areaTag12.AreaTagType = areaTagTypeByName12;
				areaTag12.GetParameter("引线").Set(0);
				AreaTag areaTag13 = doc.Create.NewAreaTag(viewPlan, area, uv);
				AreaTagType areaTagTypeByName13 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[2]);
				areaTag13.AreaTagType = areaTagTypeByName13;
				areaTag13.GetParameter("引线").Set(0);
				uv5 = new UV(uv.U, uv.V - 1.4);
				AreaTag areaTag14 = doc.Create.NewAreaTag(viewPlan, area, uv5);
				AreaTagType areaTagTypeByName14 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[3]);
				areaTag14.AreaTagType = areaTagTypeByName14;
				areaTag14.GetParameter("引线").Set(0);
				uv5 = new UV(uv.U, uv.V - 2.8);
				AreaTag areaTag15 = doc.Create.NewAreaTag(viewPlan, area, uv5);
				AreaTagType areaTagTypeByName15 = ModifyBonudaryManager.GetAreaTagTypeByName(doc, insideLabels[4]);
				areaTag15.AreaTagType = areaTagTypeByName15;
				areaTag15.GetParameter("引线").Set(0);
			}
		}

		private static void DeleteArea(Autodesk.Revit.DB.Document doc, ElementId areaId, List<KeyValuePair<Area, AreaBoundaryBean>> dicAreaToBoundary)
		{
			Area area = doc.GetElement(areaId) as Area;
			if (area == null)
			{
				return;
			}
			List<ElementId> list = new List<ElementId>();
			foreach (KeyValuePair<Area, AreaBoundaryBean> keyValuePair in dicAreaToBoundary)
			{
				try
				{
					if (keyValuePair.Key.Id.IntegerValue == area.Id.IntegerValue)
					{
						continue;
					}
				}
				catch (Exception)
				{
					continue;
				}
				list.AddRange(keyValuePair.Value.lstOneAreaBoundaryId);
			}
			try
			{
				foreach (IList<BoundarySegment> list2 in area.GetBoundarySegments(new SpatialElementBoundaryOptions()))
				{
					foreach (BoundarySegment boundarySegment in list2)
					{
						if (boundarySegment.GetElement(doc) != null && !list.Contains(boundarySegment.ElementId))
						{
							ModelCurve modelCurve = boundarySegment.GetElement(doc) as ModelCurve;
							doc.Delete(modelCurve.Id);
						}
					}
				}
			}
			catch
			{
			}
			doc.Delete(areaId);
		}

		private static AreaTagType GetAreaTagType(Autodesk.Revit.DB.Document doc)
		{
			AreaTagType areaTagType = null;
			foreach (Element element in new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).ToElements())
			{
				AreaTagType areaTagType2 = element as AreaTagType;
				if (areaTagType2 != null)
				{
					if (areaTagType == null)
					{
						areaTagType = areaTagType2;
					}
					if (areaTagType2.Name.IndexOf("标记") != -1)
					{
						return areaTagType2;
					}
				}
			}
			return null;
		}

		private static void LoadAreaTagFamily(Autodesk.Revit.DB.Document doc)
		{
			string text = Product.InstallLocation + "\\FamilyLib\\Family";
			string versionNumber = doc.Application.VersionNumber;
			string text2 = "盈建科面积标记";
			text = string.Concat(new string[]
			{
				text,
				"\\",
				versionNumber,
				"\\RoomTag\\",
				text2,
				".rfa"
			});
			if (!File.Exists(text))
			{
				YJKMessageBox.Show(text + "文件不存在。");
			}
			doc.LoadFamily(text);
		}

		private static AreaTagType GetAreaTagTypeByName(Autodesk.Revit.DB.Document doc, string symbolName)
		{
			foreach (Element element in new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).ToElements())
			{
				AreaTagType areaTagType = element as AreaTagType;
				if (areaTagType != null && symbolName.ToUpper().CompareTo(areaTagType.Name.ToUpper()) == 0)
				{
					return areaTagType;
				}
			}
			return null;
		}

		private static List<string> GetInsideLabels(Area area)
		{
			string text = area.GetParameter("名称").AsString();
			string text2 = area.GetParameter("区域编号").AsString();
			string text3 = area.GetParameter("区域单元").AsString();
			string text4 = area.GetParameter("区域楼号").AsString();
			List<string> list = new List<string>();
			if (text.Length > 0)
			{
				list.Add("名称");
			}
			if (text2.Length > 0)
			{
				list.Add("编号");
			}
			if (text3.Length > 0)
			{
				list.Add("单元");
			}
			if (text4.Length > 0)
			{
				list.Add("楼号");
			}
			list.Add("面积平方米");
			return list;
		}

		public static bool HaxExtensibleStorageInArea(Area area, ref AreaType areaType)
		{
			areaType = AreaType.AT_None;
			Schema schema = Schema.Lookup(new Guid(ModifyBonudaryManager.m_GUID));
			if (schema == null)
			{
				return false;
			}
			Entity entity = area.GetEntity(schema);
			if (entity == null)
			{
				return false;
			}
			if (entity.Schema == null)
			{
				return false;
			}
			Field field = schema.GetField(ModifyBonudaryManager.m_AreaTypeFieldName);
			areaType = (AreaType)entity.Get<int>(field);
			return areaType != AreaType.AT_None;
		}

		public static bool judgeCurRoomIsInArea(Autodesk.Revit.DB.Document doc, List<KeyValuePair<Area, AreaBoundaryBean>> lstarea, int row, ref List<Room> lstInputRooms)
		{
			List<ElementId> list = new List<ElementId>();
			List<KeyValuePair<Room, ElementId>> list2 = new List<KeyValuePair<Room, ElementId>>();
			foreach (Room room in lstInputRooms)
			{
				list2.Add(new KeyValuePair<Room, ElementId>(room, room.Id));
			}
			try
			{
				foreach (KeyValuePair<Area, AreaBoundaryBean> keyValuePair in lstarea)
				{
					if (InsertDataManager.ReadExtensibleStorageFromArea(keyValuePair.Key, ref list))
					{
						for (int i = 0; i < list2.Count; i++)
						{
							if (list.Contains(list2[i].Value))
							{
								lstInputRooms.Remove(list2[i].Key);
								list2.RemoveAt(i);
								i--;
							}
							if (lstInputRooms.Count == 0)
							{
								return true;
							}
						}
					}
					if (lstInputRooms.Count != 0)
					{
						for (int j = 0; j < lstInputRooms.Count; j++)
						{
							if (YJKGeometryFuncs.Geometry.PointInPloygon(keyValuePair.Value.lstOneAreaBoundary, (lstInputRooms[j].Location as LocationPoint).Point) == 1)
							{
								lstInputRooms.Remove(lstInputRooms[j]);
								list2.RemoveAt(j);
								j--;
							}
							if (lstInputRooms.Count == 0)
							{
								return true;
							}
						}
					}
				}
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		private static bool GetAreaInnerPt(RevitPolygonDataBean tempPolygon, out XYZ innerPoint)
		{
			new List<XYZ>();
			new List<XYZ>();
			new Dictionary<XYZ, double>();
			try
			{
				List<XYZ> list = new List<XYZ>();
				XYZ xyz = new XYZ();
				foreach (Curve curve in tempPolygon.ShellCurveLoop)
				{
					if (curve != null)
					{
						XYZ endPoint = curve.GetEndPoint(0);
						XYZ endPoint2 = curve.GetEndPoint(1);
						list.Add(new XYZ(endPoint.X, endPoint.Y, endPoint.Z));
						list.Add(new XYZ(endPoint2.X, endPoint2.Y, endPoint.Z));
					}
				}
				foreach (XYZ xyz2 in list)
				{
					xyz += xyz2;
				}
				innerPoint = new XYZ(xyz.X / (double)list.Count, xyz.Y / (double)list.Count, xyz.Z / (double)list.Count);
			}
			catch (Exception)
			{
				innerPoint = null;
				YJKMessageBox.Show("无法计算绘制后面积区域中心点!");
				return false;
			}
			return true;
		}

		private static bool TryGetIntersectionPoint(Curve inputCurveOne, Curve inputCurveTwo, out XYZ interectionPoint)
		{
			interectionPoint = null;
			IntersectionResultArray intersectionResultArray = null;
			bool result;
			try
			{
                if ((int)inputCurveOne.Intersect(inputCurveTwo, out intersectionResultArray) == 8)
				{
					interectionPoint = intersectionResultArray.get_Item(0).XYZPoint;
					result = true;
				}
				else
				{
					result = false;
				}
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		public static List<ElementId> GetDetailCurve(Autodesk.Revit.DB.Document doc)
		{
			List<ElementId> list = new List<ElementId>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc, doc.ActiveView.Id);
			ElementClassFilter elementClassFilter = new ElementClassFilter(typeof(CurveElement));
			foreach (Element element in filteredElementCollector.WherePasses(elementClassFilter).ToElements().ToList<Element>())
			{
				if (element != null && element is DetailCurve && InsertDataManager.ReadExensibleStorageToCurve(element as DetailCurve))
				{
					list.Add(element.Id);
				}
			}
			return list;
		}

		public static List<Curve> GetOneAreaBoundaryCurves(Autodesk.Revit.DB.Document doc, Area area, int nCurRow, ref List<ElementId> lstBoundaryIds)
		{
			List<Curve> list = new List<Curve>();
			List<ElementId> list2 = null;
			if (Untiltiy.m_lstBaseDataInUnit.Contains(nCurRow))
			{
				list2 = InsertDataManager.ReadArchAreaData(area);
			}
			else
			{
				if (list2 != null)
				{
					using (List<ElementId>.Enumerator enumerator = list2.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							ElementId elementId = enumerator.Current;
							if (elementId.IntegerValue != -1)
							{
								ModelCurve modelCurve = doc.GetElement(elementId) as ModelCurve;
								lstBoundaryIds.Add(elementId);
								list.Add(modelCurve.GeometryCurve);
							}
						}
						return list;
					}
				}
				bool flag = true;
				foreach (IList<BoundarySegment> list3 in area.GetBoundarySegments(new SpatialElementBoundaryOptions()))
				{
					if (flag)
					{
						foreach (BoundarySegment boundarySegment in list3)
						{
							list.Add(boundarySegment.GetCurve());
							lstBoundaryIds.Add(boundarySegment.ElementId);
						}
						flag = false;
					}
					else
					{
						foreach (BoundarySegment boundarySegment2 in list3)
						{
							list.Add(boundarySegment2.GetCurve());
							lstBoundaryIds.Add(boundarySegment2.ElementId);
						}
					}
				}
			}
			return list;
		}

		private static AreaType m_areaType = AreaType.AT_None;

		private static string m_GUID = "82FEEA0A-95F2-4D07-AB7C-73E4EFFDA615";

		private static string m_AreaTypeFieldName = "AreaType";

		private static List<XYZ> lstAreaInnerPts = new List<XYZ>();

		private static RevitPolygonRelateOperater m_useRelateOperater = new RevitPolygonRelateOperater();

		private static TopologyRelateKindEnum tempRelate;
	}
}
